import java.util.Random;
import java.util.Scanner;

/**
 * ClassName: LoopExer
 * Package: PACKAGE_NAME
 * Description:
 *
 * @Author 杨宁
 * @Create 2024/6/9 17:46
 * @Version 1.0
 */
public class LoopExer {
/*
    用户输入整数n,累计计算1到n的和
 */
/*public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.print("请输入大于0的整数：");
    int n = scanner.nextInt();
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += i;
    }
    System.out.println("1-"+n+"的和为："+sum);

}*/
   /*
   判断用户输入的数字是否为回文数
   回文数是指一个数倒着跟本身一样 如121
   */
/*
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个大于0的正整数：");
        int n = scanner.nextInt();

        int temp = n;
        // 将数字倒过来以后的值
        int com = 0;

        while(temp != 0) {
            com = com * 10 + temp % 10;
            temp /= 10;
        }
        if(com == n) {
            System.out.println(n+"是回文数！");
        }
        else {
            System.out.println(n+"不是回文数！");
        }
    }
*/
/*
    判断用户输入：1-5为工作日，6，7为休息日，其他选项不符合输入
 */
    /*public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入1-7的正整数：");
        int n = scanner.nextInt();
        switch(n) {
            case 1,2,3,4,5 -> System.out.println("星期" + n + "是工作日！");
            case 6,7 -> System.out.println("星期" + n + "是休息日！");
            default -> System.out.println("不符合输入！");
        }
    }*/

    /*
        猜数字游戏
        随机生成1-100之间的整数，用户输入猜测，提示猜大了、猜小了两种情况继续猜测，猜中了结束游戏
        最多只能猜5次
     */

    /*public static void main(String[] args) {
        Random random = new Random();
        int guessNum = random.nextInt(100) + 1;
        System.out.println("猜数为："+guessNum);
        Scanner scanner = new Scanner(System.in);
        int total = 0;
        while (true) {
            if(total >= 5) {
                System.out.print("最多猜5次，次数已用完，很遗憾没猜中，游戏结束！");
                break;
            }
            System.out.print("请输入1-100的正整数：");
            int n = scanner.nextInt();
            if(n < guessNum) {
                System.out.println("猜小了！");
            }
            else if(n > guessNum) {
                System.out.println("猜大了！");
            }
            else {
                System.out.println("猜中了！");
                break;
            }
            total++;
        }
    }*/

    /*
        逢七过 1 - 100 打印出逢七数字
     */
    /*public static void main(String[] args) {
        for (int i = 1; i <= 100; i++) {
            if(i % 7 == 0 || i % 10 == 7 || i / 10 % 10 == 7 ) {
                System.out.print(i + " ");
            }
        }


    }*/
    /*
        找出用户输入数字的平方根,只保留整数部分
     */
    /*public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个大于0的整数：");
        int n = scanner.nextInt();
        for (int i = 1; i <= n; i++) {
            if(i * i == n) {
                System.out.println(i + "是" + n + "的平方根。");
                break;
            }
            else if(i*i > n) {
                System.out.println((i-1) + "是" + n + "的平方根。");
                break;
            }
        }

    }*/

    /*
        判断是否为质数
     */
    /*public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个大于0的整数：");
        int n = scanner.nextInt();
        boolean bool = true;
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if(n % i == 0) {
                bool = false;
                break;
            }
        }
        if(bool) {
            System.out.println(n + "是质数。");
        }
        else {
            System.out.println(n + "不是质数。");
        }
    }*/

}
